// =============================================================================
//  STATS - Statistical Analysis Tools, v.0.01
//  Copyright (C) 2012  Vettigli Marco
// -----------------------------------------------------------------------------
//
// This program  is free software:  you can  redistribute it and/or  modify it
// under the terms of the  GNU General Public License as published by the Free
// Software Foundation,  either version 3 of the License,  or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY;  without even  the  implied  warranty  of  MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License  for
// more details.
//
// You  should  have received a copy of the  GNU General Public License  along
// with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// == module ===================================================================
//
// DIALOGINSERTCOLUMNS.CPP
// The class defines a graphical user interface for columns insertion.
//
// Author: Vettigli Marco
//
// TODO: write DialogInsertColumns module documentation
//
// == implementation ===========================================================
//
// TODO: write DialogInsertColumns implementation documentation
//
// =============================================================================

// == include directives =======================================================

#include "dialoginsertcolumns.h"
#include "ui_dialoginsertcolumns.h"

// == constructors and destructors =============================================

DialogInsertColumns::DialogInsertColumns(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogInsertColumns)
{
    ui->setupUi(this);
}

DialogInsertColumns::~DialogInsertColumns()
{
    delete ui;
}

// == getters ==================================================================

QString DialogInsertColumns::getColumnName() const
{
    return ui->lineName->text();
}

int DialogInsertColumns::getColumnNumber() const
{
    return ui->spinNumber->value();
}

StatS::SColProperty::ArrayType DialogInsertColumns::getColumnType() const
{
    switch (ui->comboContent->currentIndex()) {
    case 0: return StatS::SColProperty::SDoubles;
    case 1: return StatS::SColProperty::SStrings;
    default: return StatS::SColProperty::Undefined;
    }
}

DialogInsertColumns::Position DialogInsertColumns::getInsertionPosition() const
{
    if (ui->checkAfterSel->isChecked())
        return DialogInsertColumns::AfterSelected;
    if (ui->checkBeforeSel->isChecked())
        return DialogInsertColumns::BeforeSelected;
    if (ui->checkBegin->isChecked())
        return DialogInsertColumns::Begin;
    if (ui->checkEnd->isChecked())
        return DialogInsertColumns::End;
    // the flow should never reach this point
    return DialogInsertColumns::BeforeSelected;
}

// == setters ==================================================================

bool DialogInsertColumns::setColumnName(const QString name)
{
    ui->lineName->setText(name);
    return true;
}

bool DialogInsertColumns::setColumnNumber(int number)
{
    if (number < 1) return false;
    ui->spinNumber->setValue(number);
    return true;
}

bool DialogInsertColumns::setColumnType
(const StatS::SColProperty::ArrayType type)
{
    switch (type) {
    case StatS::SColProperty::SDoubles:
        ui->comboContent->setCurrentIndex(0);
        return true;
    case StatS::SColProperty::SStrings:
        ui->comboContent->setCurrentIndex(1);
        return true;
    case StatS::SColProperty::Undefined:
        ui->comboContent->setCurrentIndex(-1);
        return true;
    default: return false;
    }
}

bool DialogInsertColumns::setInsertionPosition(
    DialogInsertColumns::Position pos)
{
    // based on pos argument check the proper checkbox
    switch (pos) {
    case DialogInsertColumns::AfterSelected:
        ui->checkAfterSel->setChecked(true);
        return true;
    case DialogInsertColumns::BeforeSelected:
        ui->checkBeforeSel->setChecked(true);
        return true;
    case DialogInsertColumns::Begin:
        ui->checkBegin->setChecked(true);
        return true;
    case DialogInsertColumns::End:
        ui->checkEnd->setChecked(true);
        return true;
    default: return false;
    }
}

// == inspectors ===============================================================

// == accessor function definitions ============================================

// == static variables =========================================================

// == static funtion definitions ===============================================

// == private function definitions =============================================

void DialogInsertColumns::on_buttonBox_accepted()
{
    this->accept();
}

void DialogInsertColumns::on_buttonBox_rejected()
{
    this->reject();
}
